package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.Company;
import com.yiya.bean.SysUser;
import com.yiya.mapper.CompanyMapper;
import com.yiya.model.CompanyCplex;
import com.yiya.model.CompanyCplexModel;

@Service("companyService")
public class CompanyService{
	@Autowired
	private CompanyMapper companyMapper;

	public List<CompanyCplex> queryByList(CompanyCplexModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<CompanyCplex> list = companyMapper.selectByModel(bean);
		return list;
	}

	public int queryByCount(CompanyCplexModel bean) {
		return companyMapper.countByModel(bean);
	}
	
	public int add(Company bean){
		return companyMapper.insert(bean);
	}
	
	public int Update(Company bean){
		return companyMapper.updateByPrimaryKeySelective(bean);
	}
	
	public Company queryById(Integer id){
		return companyMapper.selectByPrimaryKey(id);
	}
	
	public void delete(Integer[] ids,SysUser user){
		for(Integer id:ids){
			Date nowTime = new Date();
			Company bean = companyMapper.selectByPrimaryKey(id);
			bean.setUpdateBy(user.getId());
			bean.setUpdateTime(nowTime);
			bean.setDelFlag(1);
			companyMapper.updateByPrimaryKeySelective(bean);
		}
	}
	
	public List<CompanyCplex> getCompanyList(CompanyCplexModel bean){
		return companyMapper.selectCompany(bean);
	}
	
	/**
	 * 获取过期的公司
	 * @param bean
	 */
	public List<Company> getExpireCompany(){
		return companyMapper.selectExpireCompany();
	}
}
